
import tkinter as tk

from tkinter import ttk

class  Windows:
    def __init__(self):
        self.root = tk.Tk()
        self.root.geometry('800x600+200+50')
        self.button = tk.Button(self.root,text='插入数据',command=self.insert)
        self.button.pack()
        # 提前准备列标签名字与中文显示内容
        columns = [
            "name", "chinese", "math", "english", 'total',

        ]
        # 使用ttk创建一个树状图
        self.tree_view = ttk.Treeview(self.root,
                                      show="headings",
                                      columns=columns,
                                      height=10,
                                        )
        # 设置列名
        self.tree_view.column('name', width=80,
                              anchor='center')
        self.tree_view.column('chinese', width=80,
                              anchor='center')
        self.tree_view.column('math', width=80,
                              anchor='center')
        self.tree_view.column('english', width=80,
                              anchor='center')
        self.tree_view.column('total', width=80,
                              anchor='center')

        # 给列名设置显示的名字
        self.tree_view.heading('name', text='姓名')
        self.tree_view.heading('chinese', text='语文')
        self.tree_view.heading('math', text='数学')
        self.tree_view.heading('english', text='英语')
        self.tree_view.heading('total', text='总分')
        self.tree_view.place(relx=0.18, rely=0.17)
    def insert(self):
        data=[['张三',99,83,23,205],['李四',22,33,44,99]]
        index=0
        for i in data:
            self.tree_view.insert('',index=index,values=(i[0],i[1],i[2],i[3],i[4]))
            index=index+1
a=Windows()
a.root.mainloop()